package Lee_code;

/**
 * @author blh
 * @date 2024年11月15日 8:40
 * 最少翻转次数使二进制矩阵回文 I
 */
public class Lee_3239_1115 {
    public int minFlips(int[][] grid) {
        int m = grid.length;
        int n = grid[0].length;
        // 遍历行
        int resRow = 0;
        for (int[] ints : grid) {
            int l = 0, r = n - 1;
            int tempRes = 0;
            while (l < r) {
                if (ints[l] != ints[r]) {
                    tempRes++;
                }
                l++;
                r--;
            }
            resRow += tempRes;
        }
        // 遍历列
        int resColumn = 0;
        for (int i = 0; i < n; i++) {
            int tempRes = 0;
            int l = 0, r = m - 1;
            while (l < r) {
                if (grid[l][i] != grid[r][i]) {
                    tempRes++;
                }
                l++;
                r--;
            }

            resColumn += tempRes;
        }
        return Math.min(resRow, resColumn);
    }

    public static void main(String[] args) {
        Lee_3239_1115 method = new Lee_3239_1115();
        method.minFlips(new int[][]{{0, 1}, {0, 1}, {0, 0}});

    }
}
